package com.jason.kotlin.gank.ui.section

import android.content.Context
import android.view.View
import android.widget.TextView
import com.jason.kotlin.gank.R
import com.jason.kotlin.gank.model.GankDataBean
import com.jason.kotlin.gank.ui.manage.PageManager
import com.jason.library.common.base.IViewSection
import com.maning.library.SwitcherView
import java.util.*

class GankGirlSection(context: Context) : IViewSection<List<GankDataBean>>(context) {

    private lateinit var headLoading: TextView
    private lateinit var switcherView: SwitcherView

    override fun populateView() {
        headLoading = rootView.findViewById(R.id.tv_loading_headline)
        switcherView = rootView.findViewById(R.id.switcherView)
        headLoading.visibility = View.VISIBLE
        switcherView.visibility = View.GONE
    }

    override fun getLayoutId() = R.layout.item_girl_header

    override fun setData(data: List<GankDataBean>) {
        headLoading.visibility = View.GONE
        switcherView.visibility = View.VISIBLE

        val headStrs = ArrayList<String>()
        if (data.size > 0) {
            for (i in data.indices) {
                headStrs.add(data.get(i).desc)
            }
        }

        switcherView.setResource(headStrs)
        //开始滚动
        switcherView.startRolling()
        //点击事件
        switcherView.setOnClickListener(View.OnClickListener {
            val index: Int = switcherView.getCurrentIndex()
            val randomData: GankDataBean = data.get(index)
            PageManager.openWebPage(context,
                randomData.type,
                randomData.title,
                randomData.url)
        })
    }
}